package com.hopu.pyq.controller;

import com.hopu.pyq.entity.User;
import com.hopu.pyq.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpSession;

@Controller
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("login")
    public String login(String username, String password, HttpSession session, Model model){
        User user = userService.login(username, password);
        if(user == null){
            model.addAttribute("error","账号或密码错误");
            return "login";
        }
        session.setAttribute("user",user);
        return "redirect:/findAllPyq";
    }
}
